//根据localstorage的数据字典初始化下拉框
function renderSelectOptions(data, settings, name) {
    settings = settings || {};
    var valueField = settings.valueField || 'value',
        textField = settings.textField || 'text',
        selectedValue = settings.selectedValue || "";
    var html = [];

    //插入空白选项
    html.push('<option value="">选择' + name + '</option>');

    for (var i = 0, item; i < data.length; i++) {
        item = data[i];
        html.push('<option value="');
        html.push(item[valueField]);
        html.push('"');
        if (selectedValue && item[valueField] == selectedValue) {
            html.push(' selected="selected"');
        }
        html.push('>');
        html.push(item[textField]);
        html.push('</option>');
    }

    return html.join('');
}

//根据数据字典翻译ID为名称
function renderItemName(data, id) {
    for (var i = 0, item; i < data.length; i++) {
        item = data[i];

        if (item.id == id) {
            return item.name;
        }
    }
}

//弹出加载等待框
function showLoad() {
    return layer.msg('拼命执行中...', { icon: 16, shade: [0.5, '#f5f5f5'], scrollbar: false, offset: 'auto', time: 100000 });
}

//关闭加载等待框
function closeLoad(index) {
    layer.close(index);

}

function showSuccess(msg) {
    if (msg) {
        layer.msg(msg, { time: 1000, offset: 'auto' });
    } else {
        layer.msg('执行成功！', { time: 1000, offset: 'auto' });
    }

}

//获取URL 参数
function getQueryString(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    }
    return null;
}

//获取contextpath
function getContextPath() {
    var pathName = document.location.pathname;
    var index = pathName.substr(1).indexOf("/");
    var result = pathName.substr(0, index + 1);
    return result;
}

/**
 * 全局contextPath
 */
var contextPath=getContextPath();